//
//  SCNRankingTableViewCell.swift
//  ShoucainuSwift
//
//  Created by 王家旭 on 2017/5/12.
//  Copyright © 2017年 Riluee. All rights reserved.
//

import UIKit

class SCNRankingTableViewCell: UITableViewCell {

    var index: Int {
        set {
            //排序处理
            
            if (newValue > 2) {
                gradeImageView.isHidden = true
                gradeL.text = "\(newValue + 1)"
                gradeL.isHidden = false
            }else {
                //皇冠逻辑

                let imgNameString = newValue == 0 ? "jin_icon":newValue == 1 ? "yin_icon":"tong_icon"
                
                gradeImageView.image = UIImage(named: imgNameString)
                gradeImageView.isHidden = false
                gradeL.isHidden = true
            }

        }
        get {
            return self.index
        }
    }
    
    
    // 奖牌🏅
    lazy var gradeImageView: UIImageView = {
        
        let imgView = UIImageView()
        return imgView
    }()
    // 等级
    lazy var gradeL: UILabel = {
        
        let lab = UILabel()
        lab.backgroundColor = SCNConstants.colorWith255RGBA(0, g: 122, b: 255, a: 1)
        lab.textColor = .white
        lab.font = UIFont.systemFont(ofSize: 15.5)
        lab.layer.cornerRadius = 11
        lab.layer.masksToBounds = true
        lab.textAlignment = .center
        return lab
    }()
    // 名称
    lazy var titleL: UILabel = {
        
        let lab = UILabel()
        lab.textColor = SCNConstants.colorFromHexValue(0x333333, alpha: 1)
        lab.font = UIFont.systemFont(ofSize: 15.5)
        return lab
    }()
    // 金额
    lazy var detailL: UILabel = {
        
        let lab = UILabel()
        lab.textColor = SCNConstants.colorFromHexValue(0x333333, alpha: 1)
        lab.font = UIFont.systemFont(ofSize: 15.5)
        lab.textAlignment = .center
        return lab
    }()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        contentView.addSubview(gradeImageView)
        contentView.addSubview(gradeL)
        contentView.addSubview(titleL)
        contentView.addSubview(detailL)
        
        gradeImageView.snp.makeConstraints { (make) in
            make.leading.equalTo(22)
            make.top.equalTo(9)
            make.size.equalTo(CGSize(width: 32,height: 19))
        }
        gradeL.snp.makeConstraints { (make) in

            make.leading.equalTo(27)
            make.top.equalTo(11)
            make.size.equalTo(CGSize(width: 22,height: 22))
        }
        titleL.snp.makeConstraints { (make) in
           
            make.leading.equalTo(80)
            make.top.equalTo(0)
            make.size.equalTo(CGSize(width: 100,height: 44))
        }
        detailL.snp.makeConstraints { (make) in
            make.leading.equalTo(180)
            make.top.equalTo(0)
            make.size.equalTo(CGSize(width: SCNConstants.SCREENWIDTH - 180,height: 44))
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
